package com.dsc.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: Du Shun Chang
 * @title: LoginServlet
 * @date: 2022/2/6 23:44
 * @description: 登录
 * @version：1.0
 */
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            String username=request.getParameter("username");
            String password=request.getParameter("password");
            if (username.equals("admin") && password.equals("123")){
//            System.out.println("我进入到登录方法中");
                System.out.println(username+"  "+password);
                response.sendRedirect("/JavaWeb_demo_4_ForwardRedirection_war/success.jsp");//重定向到success.jsp
            }else{
                request.getRequestDispatcher("error.jsp").forward(request, response);//转发到error.jsp
                request.setAttribute("msg", "账户或密码错误");
            }


    }
}
